package com.example.combwx.mvp.model;

import com.example.combwx.mvp.base.model.BaseEntity;
import com.example.combwx.mvp.base.model.BaseModel;
import com.example.combwx.mvp.contract.UserContract;
import com.example.combwx.mvp.model.entity.ResponseUserEntity;
import com.example.combwx.network.Api;
import com.example.combwx.network.ChangeFunction;
import com.example.combwx.network.HttpFactory;
import com.example.combwx.network.HttpType;

import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;
import okhttp3.RequestBody;

public class UserModel extends BaseModel implements UserContract.IUserModel {

    @Inject
    public UserModel(){}

    @Override
    public Observable<BaseEntity> requestUser(Map<String, Object> map) {
        int code = (int) map.get("code");
        map.remove("code");
        if (code==HttpCode.SELUSERCODE){
            RequestBody body=createBody(map);
            Observable<ResponseUserEntity> ob= HttpFactory.getInstance().factory(HttpType.TOKENSIGNTYPE)
                    .getRetrofit().create(Api.class).requestUser(body);
            return ob.map(new ChangeFunction<ResponseUserEntity>());
        }
        return null;
    }
}
